﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace com.huawei.ebg.esdk.ucsdk.client.control
{
    public partial class ChooseDial : Button
    {
        public ChooseDial()
        {
            InitializeComponent();
        }

        # region 自定义字段

        private string _ucAccount;
        [Description("被叫UC帐号")]
        public string UCAccount
        {
            get { return _ucAccount; }
            set { _ucAccount = value; }
        }

        private Image _imgUCNumber = Properties.Resources.UCNumber;
        [Description("下拉框UCNumber帐号图片")]
        public Image IMGUCNumber
        {
            get { return _imgUCNumber; }
            set { _imgUCNumber = value; }
        }

        private Image _imgMobile = Properties.Resources.Mobile;
        [Description("下拉框Mobile帐号图片")]
        public Image IMGMobile
        {
            get { return _imgMobile; }
            set { _imgMobile = value; }
        }

        private Image _imgHomePhone = Properties.Resources.HomePhone;
        [Description("下拉框HomePhone帐号图片")]
        public Image IMGHomePhone
        {
            get { return _imgHomePhone; }
            set { _imgHomePhone = value; }
        }

        private Image _imgOfficePhone = Properties.Resources.OfficePhone;
        [Description("下拉框OfficePhone帐号图片")]
        public Image IMGOfficePhone
        {
            get { return _imgOfficePhone; }
            set { _imgOfficePhone = value; }
        }

        private Image _imgOtherPhone = Properties.Resources.OtherPhone;
        [Description("下拉框OtherPhone帐号图片")]
        public Image IMGOtherPhone
        {
            get { return _imgOtherPhone; }
            set { _imgOtherPhone = value; }
        }

        # endregion

        private static ArrayList myList;

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            try
            {
                ToolStripDropDown dropDown = new ToolStripDropDown();

                //查询被叫用户号码，号码存在ArrayList里，返回此ArrayList
                myList = CtrlBusiness.GetPhoneNbr(this.UCAccount);
                if (myList != null && myList.Count > 0)
                {
                    //遍历ArrayList的号码，显示在此ToolStripDropDown上
                    for (int i = 0; i < myList.Count; i++)
                    {
                        if (Utilities.ItemExisted(myList[i].ToString()))
                        {
                            //如果ArrayList的号码不为空，则生成一个ToolStripButton，并加入ToolStripDropDown里
                            ToolStripButton tsButton = new ToolStripButton();
                            tsButton.Text = myList[i].ToString();
                            //设置ToolStripButton的图标
                            tsButton.Image = GetPhoneImage(i);
                            tsButton.Click += new EventHandler(tsButton_Click);
                            dropDown.Items.Add(tsButton);
                        }
                    }

                    //设置ToolStripDropDown弹出位置
                    Point location = Utilities.GetClientLocation(this, dropDown);
                    dropDown.Show(this, location, ToolStripDropDownDirection.BelowRight);
                }
            }
            catch (Exception ex)
            {
                //throw ex;
            }
        }

        private void tsButton_Click(object sender, EventArgs e)
        {
            try
            {
                string myNumber = ((ToolStripButton)sender).Text;
                //myList第一个号码固定为UC帐号，如果选择的号码是UC帐号，则以UC帐号进行呼叫
                if (myList[0].ToString() != string.Empty && myList[0].ToString() == myNumber)
                {
                    CtrlBusiness.DirectCall(myNumber, string.Empty);
                }
                else
                {
                    CtrlBusiness.DirectCall(string.Empty, myNumber);
                }
            }
            catch (System.Exception ex)
            {
            	
            }

           
        }

        private Image GetPhoneImage(int seq)
        {
            switch (seq)
            {
                case 0:
                    return _imgUCNumber;
                case 1:
                    return _imgMobile;
                case 2:
                    return _imgHomePhone;
                case 3:
                    return _imgOfficePhone;
                case 4:
                    return _imgOtherPhone;
                default:
                    return _imgOtherPhone;
            }
        }
    }
}
